Skip to content

Conversation

@surenkov
Copy link
Contributor

@surenkov surenkov commented Nov 24, 2025

This PR updates the Gemini backend to preserve thoughtSignature fields, which is mandatory for Gemini 3 Pro and recommended for Gemini 2.5.

Gemini reasoning models return an encrypted thoughtSignature alongside text or function calls to maintain reasoning context in their stateless API. Per Gemini API specifications:

When using Gemini 3 Pro, you must pass back thought signatures during function calling, otherwise you will get a validation error (4xx status code).

Previously, gptel-gemini discarded this signature. This change ensures the signature is retained and sent back in the conversation history for subsequent turns, preventing API errors with reasoning models.

Changes:

  • Response Parsing:
    • The thoughtSignature is extracted and attached to the tool-use plist :id property if a functionCall is present and the signature is supplied in the response.
    • For text responses, the thoughtSignature is stored as a 'gptel-gemini-thought-signature text property on the response content in the buffer.
  • History Extraction:
    • The signature is retrieved from the text property for model text responses and from the tool call plist for model function calls.
    • The retrieved thoughtSignature is then included in the message structure sent back to the Gemini API.

Closes #1146

@surenkov surenkov force-pushed the master branch 2 times, most recently from d8732c3 to 385fc46 Compare November 27, 2025 11:28
@surenkov surenkov marked this pull request as draft November 27, 2025 20:55
@surenkov surenkov closed this Nov 29, 2025
@surenkov surenkov reopened this Nov 29, 2025
@surenkov surenkov force-pushed the master branch 3 times, most recently from b18c8cb to 2b930c2 Compare November 29, 2025 15:49
@surenkov surenkov marked this pull request as ready for review December 1, 2025 08:59
@surenkov surenkov marked this pull request as draft December 4, 2025 16:18
@surenkov surenkov force-pushed the master branch 6 times, most recently from e8d2063 to 1488db6 Compare December 7, 2025 13:36
@surenkov surenkov marked this pull request as ready for review December 7, 2025 14:02
surenkov added a commit to surenkov/gptel-test that referenced this pull request Dec 8, 2025
Also fix `model` parts, transforming them into vectors of plists, in accordance to Gemini API.

This should play in conjunction with karthink/gptel#1154
@surenkov
Copy link
Contributor Author

surenkov commented Dec 8, 2025

Strictly speaking, I haven't got any idea better than to put the signature as an :id of the tool call. At least Gemini does not provide real call ids, and placing the signatures there doesn't break any existing behavior, allowing to carry them across multiple conversation turns.

@karthink can you please take a look at these changes? Is there a better place of storing these signatures?

@karthink
Copy link
Owner

karthink commented Dec 8, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support gemini thought_signature

2 participants